/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sessionBeans;

import entidades.Pregunta;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author SiperProg
 */
@Stateless
public class PreguntaFacade extends AbstractFacade<Pregunta> {

    @PersistenceContext(unitName = "EncuestaPU")
    private EntityManager em;

    @Override
    protected EntityManager getEntityManager() {
        return em;
    }

    public PreguntaFacade() {
        super(Pregunta.class);
    }

    public List<Pregunta> getPreguntas(Long servId, Boolean preOblig) {
        List<Pregunta> preguntas;
        if (preOblig) {
            preguntas = em.createQuery("SELECT p FROM Pregunta p WHERE p.preOblig = :preOblig").setParameter("preOblig", preOblig).getResultList();
        } else {
            preguntas = em.createQuery("SELECT p FROM Pregunta p WHERE p.servId = :servId and p.preOblig = :preOblig").setParameter("servId", servId).setParameter("preOblig", preOblig).getResultList();
        }

        return preguntas;
    }

}
